package com.sunnada.edu.system.pub.common;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sunnada.edu.system.pub.dao.BaseDao;
import com.sunnada.edu.system.pub.dao.BaseDaoImpl;
import com.sunnada.edu.system.pub.dao.PubDao;



public class AppContext {
	public static ApplicationContext ctx;
	public static AppContext act;
	private static String rootPath;

	public static AppContext getInstance() {
		if (act == null) {
			synchronized (AppContext.class) {
				if (act == null) {
					act = new AppContext();
				}
			}
		}
		return act;
	}

	public PubDao getPubDao() {
		PubDao dao = (PubDao) ctx.getBean("pubDao");
		return dao;
	}
	
	public Object getBean(String beanId){
		return (Object)ctx.getBean(beanId);
	}

	public static ApplicationContext getCtx() {
		return ctx;
	}

	public static void setCtx() {
		try {
			String[] s = new String[] { "applicationContext-ibatis.xml" };
			ctx = new ClassPathXmlApplicationContext(s);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String getRootPath() {
		return rootPath;
	}

	public static void setRootPath(String rootPath) {
		AppContext.rootPath = rootPath;
	}
}
